package com.bocai.kelala.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.bocai.kelala.R;

/**
 * Created by yuanfei on 2017/6/15.
 */

public class SorryDialog {
    private Context context;
    private Dialog dialog;
    private Display display;
    private Button btnNext;
    private LinearLayout lLayout_bg;


    public SorryDialog(Context context) {
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }
    public SorryDialog builder(){
        // 获取Dialog布局
        View view = LayoutInflater.from(context).inflate(
                R.layout.view_sorry_dialog, null);
        btnNext = (Button) view.findViewById(R.id.btn_next);
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);


        // 定义Dialog布局和参数
        dialog = new Dialog(context, R.style.AlertDialogStyle);
        dialog.setContentView(view);

        // 调整dialog背景大小
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display
                .getWidth() * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT));
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        return this;
    }


    public void show() {
        dialog.show();
    }



}
